<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>冒泡</title>
    <style>
        .box {
            margin: 50px auto;
            width: 300px;
            height: 300px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box" id="box">
        <button id="btn">点击</button>
    </div>
</body>
<script>
    // var btn = document.querySelector('button')
    // var box = document.querySelector('.box')
    var btn = document.getElementById('btn')
    var box = document.getElementById('box')
    btn.onclick = function (event) {
        event = event || window.event
        console.log('btn');
        // 阻止冒泡
        if (event.stopPropagation) {
            event.stopPropagation()
        } else {
            //ie
            event.cancelBubble = true
        }

    }
    box.onclick = function () {
        console.log('box');
    }


    document.onclick = function () {
        console.log('document');
    }
</script>

</html>